import { exportRecord, revokeInsure } from '../../api/long-insure'
import { openDocument } from '../../../utils/util'
const app = getApp()
Component({
    data: {
        arr:['导出']
    },
    properties: {
        data: Object
    },
    methods: {
        async onExport(){
            if(this.properties.data.isAllowRevoke && this.properties.data.managerId != 1){ 
                this.setData({ 
                    arr:['导出', '撤销'] 
                })  
            }
            const event = await wx.showActionSheet({
              itemList: this.data.arr
            })
            if(event.tapIndex === 0){ 
                const file = await exportRecord({ 
                    id: this.data.data.id 
                }) 
                const url = app.globalData.baseUrl + '/common/download?fileName=' + file + 
                '&delete=false' 
                openDocument(url, file) 
            }else{
                await revokeInsure({ 
                    id:this.properties.data.id, 
                    companyPlanId:this.properties.data.companyPlanId 
                }) 
                await this.triggerEvent('revoke') 
                await app.toast('撤销成功') 
            }
        },
    }
})